package com.lesson3.singleton;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/8/27 10:17
 * 饿汉式静态代码块
 */
public class Type2
{
    public static void main(String[] args)
    {
        Singleton2 instance = Singleton2.getInstance();
        Singleton2 instance1 = Singleton2.getInstance();
        System.out.println(instance.hashCode()==instance1.hashCode());
    }
}

class Singleton2{
    private Singleton2(){

    }

    private static Singleton2 singleton2;

    static {
        singleton2 = new Singleton2();
    }

    public static Singleton2 getInstance(){
        return singleton2;
    }
}
